package com.ruoyi.sales.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.sales.domain.SalesOrder;
import com.ruoyi.sales.service.ISalesOrderService;
import com.ruoyi.api.dto.SalesOrderDTO;

/**
 * 销售订单API服务实现类
 * 
 * @author ruoyi
 * @date 2025-06-21
 */
@Service("apiSalesOrderService")
public class SalesOrderApiServiceImpl implements com.ruoyi.api.service.ISalesOrderService 
{
    @Autowired
    private ISalesOrderService salesOrderService;

    /**
     * 通过订单ID查询销售订单
     * 
     * @param orderId 订单ID
     * @return 销售订单信息
     */
    @Override
    public SalesOrderDTO getSalesOrderById(Long orderId) 
    {
        SalesOrder order = salesOrderService.selectSalesOrderByOrderId(orderId);
        return convertToDTO(order);
    }
    
    /**
     * 将实体对象转换为DTO
     * 
     * @param order 订单实体
     * @return 订单DTO
     */
    private SalesOrderDTO convertToDTO(SalesOrder order) 
    {
        if (order == null) {
            return null;
        }
        
        SalesOrderDTO dto = new SalesOrderDTO();
        dto.setOrderId(order.getOrderId());
        dto.setOrderCode(order.getOrderCode());
        dto.setCustomerId(order.getCustomerId());
        dto.setCustomerName(order.getCustomerName());
        dto.setProductId(order.getProductId());
        dto.setProductName(order.getProductName());
        dto.setCategoryId(order.getCategoryId());
        dto.setQuantity(order.getQuantity());
        dto.setUnitPrice(order.getUnitPrice());
        dto.setOrderDate(order.getOrderDate());
        dto.setTotalAmount(order.getTotalAmount());
        dto.setOrderStatus(order.getOrderStatus());
        dto.setAuditStatus(order.getAuditStatus());
        
        return dto;
    }
} 